﻿using Framework.Core;
using Framework.Core.Io;
using Framework.Remoting.Conventions;
using Xunit;

namespace Framework.Tests.Wcf.Conventions
{
    public class HostConfigurationTest
    {
        private readonly IConfigurationManagerAdapter target = new ConfigurationManagerAdapter();

        [Fact]
        public void Test_GetSection_Succeed()
        {
            var section = target.GetSection<IEnvironments, HostConfiguration>();

            var environment = section.GetEnvironment(EnvMode.Prod);

            Assert.NotNull(environment);
            Assert.Equal(EnvMode.Prod, environment.EnvMode);
            Assert.Equal("localhost", environment.Host);
            Assert.Equal(10300, environment.Port);
            Assert.Equal("netTcpBinding", environment.BindingType);
        }

        [Fact]
        public void When_EnvMode_not_configured_GetSection_throw_EnvModeNotFoundException()
        {
            var e = Assert.Throws<EnvModeNotFoundException>(
                () =>
                {
                    target.GetSection<IEnvironments, HostConfiguration>().GetEnvironment(EnvMode.Hom);
                });
            Assert.Equal("HostConfiguration was not found for environment : Hom", e.Message);
        }
    }
}